package com.lanqiao.gxnushop.mapper;

import com.lanqiao.gxnushop.entity.Products;
import com.lanqiao.gxnushop.valueObject.ProductsF;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;


@Schema(description ="商品表")
@Mapper
public interface ProductsMapper {
    @Schema(description ="添加商品")
    @Insert("insert into products(productId,storeId,name,description,imageUrl,price,stock,state,goodsCategory,zcsj) values (#{productId},#{storeId},#{name},#{description},#{imageUrl},#{price},#{stock},#{state},#{goodsCategory},now())")
    boolean add(Products products);

    @Schema(description ="删除商品")
    @Delete("delete from products where productId=#{productId}")
    boolean delete(String productId);

    @Schema(description="根据商品名称模糊查询")
    @Select("select * from products where name like concat('%',#{name},'%')")
    ArrayList<Products> findByName(String name);

    @Schema(description ="根据商品id查询商品")
    @Select("select * from products where productId=#{productId}")
    Products findById(String productId);

    @Schema(description ="更新商品")
    @Update("update products set name=#{name},description=#{description},price=#{price},stock=#{stock},state=#{state},goodsCategory=#{goodsCategory} where productId=#{productId}")
    boolean update(Products products);

    @Schema(description ="更新商品库存!")
    @Update("update products set stock=#{stock} where productId=#{productId}")
    boolean updateStock(@Param("productId") String productId,@Param("stock") String stock);

    /**商家查看自己 单个店铺 下的商品**/
    @SelectProvider(type = ProductsMapperProvide.class,method = "getProductsListSql")
    ArrayList<Products> findByStoreId(Products products);

    /**查看所有商品，用于首页商品展示*/
    @Select("select * from products where state='1'")
    ArrayList<Products> list();

    /**通过商品名字模糊查看商品，用于首页    用户搜索商品  */
    @Select("select * from products where name like concat('%',#{name},'%')")
    ArrayList<Products> selectByName(String name);

    /**通过商品名字模糊查看商品，用于首页    用户搜索商品  */
    @Select("select * from products where  name like concat('%',#{name},'%') AND state = '1'")
    ArrayList<Products> selectByName2(String name);

    /**通过商品分类查看商品，用户搜索商品  */
    @Select("select * from products where goodsCategory=#{goodsCategory} AND state = '1'")
    ArrayList<Products> selectByGoodsCategory(String goodsCategory);

    /** 商家库存管理 */
    @SelectProvider(type = ProductsMapperProvide.class,method = "getStockSql")
    ArrayList<Products> getStock(ProductsF productsF);

    /**上传商品的图片*/
    @Update("update products set imageUrl=#{imageUrl} where productId=#{productId}")
    boolean updateImgUrl(Products products);

}
